package au.edu.qut.bpm.genbinder.genetic.evaluation.costmodels;

import java.util.Iterator;
import au.edu.qut.bpm.genbinder.models.Activity;
import au.edu.qut.bpm.genbinder.models.Case;
import au.edu.qut.bpm.genbinder.models.ConcreteEventLog;
import au.edu.qut.bpm.genbinder.models.Resource;

public class CostCalculations {

	public double calculateCost(ConcreteEventLog candidate, double TIMEUNIT, long HORIZON, long HORIZONSTART) {
		double caseCost = 0, activityCost = 0, resourceCost = 0, totalCost = 0;
		
		// Cost for case (use duration and properties)
		for (Case c : candidate.getAbstractLog().getCases()) {
			String damage = null;
			double duration = ((double) candidate.getCaseDuration(c) / TIMEUNIT);
			double durInHours = duration / 60;
			double durInDays = durInHours/24;
			
			String member = null;
			
			Iterator<Activity> it = c.getActivities().iterator();

			while (it.hasNext()) {
				Activity act = (Activity) it.next();
				if (act.getAttributes().containsKey("DamageType")) {
					damage = act.getAttributes().get("DamageType").toString();
					break;
				} else {
					damage = "NA";
				}
		    }
			
			Iterator<Activity> it2 = c.getActivities().iterator();

			while (it2.hasNext()) {
				Activity act = (Activity) it2.next();
				if (act.getAttributes().containsKey("Membership")) {
					member = act.getAttributes().get("Membership").toString();
					break;
				}
		    }
			
//			System.out.println(damage + " = " + member);
			
			if (member.equalsIgnoreCase("Platinum")) {
				if (damage.equalsIgnoreCase("Windscreen")) {
					if (durInDays > 5) {
						caseCost += (1500 + 1000 + (Math.floor(durInDays - 5) * 500));
					} else {
						caseCost += 1500;
					}
				} else if (damage.equalsIgnoreCase("Scratches")) {
					if (durInDays > 5) {
						caseCost += (1500 + 1500 + (Math.floor(durInDays - 5) * 750));
					} else {
						caseCost += 1500;
					}
				} else if (damage.equalsIgnoreCase("Collision")) {
					if (durInDays > 5) {
						caseCost += (1500 + 2000 + (Math.floor(durInDays - 5) * 1500));
					} else {
						caseCost += 1500;
					}
				} else{
					caseCost += 1500;
				}
			} else if (member.equalsIgnoreCase("Gold")) {
				if (damage.equalsIgnoreCase("Windscreen")) {
					if (durInDays > 5) {
						caseCost += (500 + 1000 + (Math.floor(durInDays - 5) * 500));
					} else {
						caseCost += 500;
					}
				} else if (damage.equalsIgnoreCase("Scratches")) {
					if (durInDays > 5) {
						caseCost += (500 + 1500 + (Math.floor(durInDays - 5) * 750));
					} else {
						caseCost += 500;
					}
				} else if (damage.equalsIgnoreCase("Collision")) {
					if (durInDays > 5) {
						caseCost += (500 + 2000 + (Math.floor(durInDays - 5) * 1500));
					} else {
						caseCost += 500;
					}
				} else {
					caseCost += 500;
				}
			}
			
//			if (damage.equalsIgnoreCase("Windscreen")) {
//				caseCost += (4 * duration);
//			} else if (damage.equalsIgnoreCase("DentsAndScratches")) {
//				caseCost += (2 * duration);
//			} else if (damage.equalsIgnoreCase("Collision")) {
//				caseCost += (5 * duration);
//			} else if (damage.equalsIgnoreCase("Thief")) {
//				caseCost += (6 * duration);
//			} else if (damage.equalsIgnoreCase("Fire")) {
//				caseCost += (8 * duration);
//			} else {
//				caseCost += 0;
//			}
//			
//			if (duration >= 180) {
//				caseCost += 2000;
//				
//				double overrun = duration - 180;
//				overrun = ((int) overrun / 60);
//				caseCost += overrun * 200;
//			}
			
			
			
		}
		///*
		for (Activity a : candidate.getAllActivity()) {
			String resource = candidate.getActivityResources(a).iterator().next().toString();
			String task = a.getTask().toString();
			double actDur = ((double) candidate.getActivityDuration(a) / TIMEUNIT);
			
			if (task.equalsIgnoreCase("CAR")) {
				if (resource.equalsIgnoreCase("A1")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("A2")) {
					activityCost += (0.40 * actDur);
				}
				else if (resource.equalsIgnoreCase("A3")) {
					activityCost += (0.20 * actDur);
				}
				else if (resource.equalsIgnoreCase("A4")) {
					activityCost += (0.25 * actDur);
				}
				else if (resource.equalsIgnoreCase("A5")) {
					activityCost += (0.10 * actDur);
				}
				else if (resource.equalsIgnoreCase("A6")) {
					activityCost += (0.50 * actDur);
				}
				else if (resource.equalsIgnoreCase("A7")) {
					activityCost += (0.30 * actDur);
				}
				else if (resource.equalsIgnoreCase("A8")) {
					activityCost += (0.30 * actDur);
				}
				else if (resource.equalsIgnoreCase("A9")) {
					activityCost += (0.25 * actDur);
				}
				else if (resource.equalsIgnoreCase("A10")) {
					activityCost += (0.10 * actDur);
				}
				else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("RAR")) {
				if (resource.equalsIgnoreCase("IS1")) {
					activityCost += (1.00 * actDur);
				}
				else if (resource.equalsIgnoreCase("IS2")) {
					activityCost += (0.50 * actDur);
				}
				else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("RAR")) {
				if (resource.equalsIgnoreCase("IS1")) {
					activityCost += (1.00 * actDur);
				}
				else if (resource.equalsIgnoreCase("IS2")) {
					activityCost += (0.50 * actDur);
				}
				else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("NCU")) {
				if (resource.equalsIgnoreCase("A1")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A2")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A3")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A4")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A5")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A6")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A7")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A8")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A9")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("A10")) {
					activityCost += (0.10 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("PVA")) {
				if (resource.equalsIgnoreCase("SC1")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("SC2")) {
				activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("SC3")) {
				activityCost += (0.10 * actDur);
				} else {
				activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("ATT")) {
				if (resource.equalsIgnoreCase("SC1")) {
					activityCost += (0.35 * actDur);
				} else if (resource.equalsIgnoreCase("SC2")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("SC3")) {
					activityCost += (0.20 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("RCV")) {
				if (resource.equalsIgnoreCase("F1")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F2")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F3")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F4")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F5")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F6")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F7")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F8")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F9")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F10")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F11")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F12")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F13")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F14")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F15")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F16")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F17")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F18")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F19")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F20")) {
					activityCost += (0.10 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("ASD")) {
				if (resource.equalsIgnoreCase("F1")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F2")) {
					activityCost += (0.45 * actDur);
				} else if (resource.equalsIgnoreCase("F3")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F4")) {
					activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("F5")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F6")) {
					activityCost += (0.25 * actDur);
				} else if (resource.equalsIgnoreCase("F7")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("F8")) {
					activityCost += (0.30 * actDur);
				} else if (resource.equalsIgnoreCase("F9")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F10")) {
					activityCost += (0.30 * actDur);
				} else if (resource.equalsIgnoreCase("F11")) {
					activityCost += (0.40 * actDur);
				} else if (resource.equalsIgnoreCase("F12")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F13")) {
					activityCost += (0.25 * actDur);
				} else if (resource.equalsIgnoreCase("F14")) {
					activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("F15")) {
					activityCost += (0.25 * actDur);
				} else if (resource.equalsIgnoreCase("F16")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F17")) {
					activityCost += (0.30 * actDur);
				} else if (resource.equalsIgnoreCase("F18")) {
					activityCost += (0.90 * actDur);
				} else if (resource.equalsIgnoreCase("F19")) {
					activityCost += (0.70 * actDur);
				} else if (resource.equalsIgnoreCase("F20")) {
					activityCost += (0.60 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("ERC")) {
				if (resource.equalsIgnoreCase("F1")) {
					activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("F2")) {
					activityCost += (0.25 * actDur);
				} else if (resource.equalsIgnoreCase("F3")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F4")) {
					activityCost += (0.35 * actDur);
				} else if (resource.equalsIgnoreCase("F5")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F6")) {
					activityCost += (1.30 * actDur);
				} else if (resource.equalsIgnoreCase("F7")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("F8")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F9")) {
					activityCost += (0.25 * actDur);
				} else if (resource.equalsIgnoreCase("F10")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F11")) {
					activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("F12")) {
					activityCost +=  (0.30 * actDur);
				} else if (resource.equalsIgnoreCase("F13")) {
					activityCost += (1.00 * actDur);
				} else if (resource.equalsIgnoreCase("F14")) {
					activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("F15")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F16")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F17")) {
					activityCost += (0.25 * actDur);
				} else if (resource.equalsIgnoreCase("F18")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("F19")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F20")) {
					activityCost += (0.15 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("ARP")) {
				if (resource.equalsIgnoreCase("IS1")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("IS2")) {
					activityCost += (1.00 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("RPV")) {
				if (resource.equalsIgnoreCase("F1")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("F2")) {
					activityCost += (0.80 * actDur);
				} else if (resource.equalsIgnoreCase("F3")) {
					activityCost += (0.75 * actDur);
				} else if (resource.equalsIgnoreCase("F4")) {
					activityCost += (0.70 * actDur);
				} else if (resource.equalsIgnoreCase("F5")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("F6")) {
					activityCost += (0.30 * actDur);
				} else if (resource.equalsIgnoreCase("F7")) {
					activityCost += (0.70 * actDur);
				} else if (resource.equalsIgnoreCase("F8")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("F9")) {
					activityCost += (0.90 * actDur);
				} else if (resource.equalsIgnoreCase("F10")) {
					activityCost += (0.30 * actDur);
				} else if (resource.equalsIgnoreCase("F11")) {
					activityCost += (0.30 * actDur);
				} else if (resource.equalsIgnoreCase("F12")) {
					activityCost += (0.80 * actDur);
				} else if (resource.equalsIgnoreCase("F13")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F14")) {
					activityCost += (0.40 * actDur);
				} else if (resource.equalsIgnoreCase("F15")) {
					activityCost += (0.80 * actDur);
				} else if (resource.equalsIgnoreCase("F16")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("F17")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("F18")) {
					activityCost += (0.50 * actDur);
				} else if (resource.equalsIgnoreCase("F19")) {
					activityCost += (0.80 * actDur);
				} else if (resource.equalsIgnoreCase("F20")) {
					activityCost += (0.20 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("AVC")) {
				if (resource.equalsIgnoreCase("SC1")) {
					activityCost += (0.10 * actDur);
				} else if (resource.equalsIgnoreCase("SC2")) {
					activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("SC3")) {
					activityCost += (0.20 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("SIN")) {
				if (resource.equalsIgnoreCase("BS1")) {
					activityCost += (0.25 * actDur);
				} else if (resource.equalsIgnoreCase("BS2")) {
					activityCost += (0.75 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("AVD")) {
				if (resource.equalsIgnoreCase("SC1")) {
					activityCost += (0.70 * actDur);
				} else if (resource.equalsIgnoreCase("SC2")) {
					activityCost += (1.5 * actDur);
				} else if (resource.equalsIgnoreCase("SC3")) {
					activityCost += (0.5 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("APT")) {
				if (resource.equalsIgnoreCase("SC1")) {
					activityCost += (0.15 * actDur);
				} else if (resource.equalsIgnoreCase("SC2")) {
					activityCost += (0.20 * actDur);
				} else if (resource.equalsIgnoreCase("SC3")) {
					activityCost += (0.10 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("AWO")) {
				if (resource.equalsIgnoreCase("BS1")) {
					activityCost += (0.35 * actDur);
				} else if (resource.equalsIgnoreCase("BS2")) {
					activityCost += (0.10 * actDur);
				} else {
					activityCost += 0;
				}
			} else if (task.equalsIgnoreCase("CWR")) {
				if (resource.equalsIgnoreCase("WOS1")) {
					activityCost += (1.00 * actDur);
				} else if (resource.equalsIgnoreCase("WOS2")) {
					activityCost += (0.50 * actDur);
				} else {
					activityCost += 0;
				}
			} else {
				activityCost += 0;
			}

			
//			if (task.equalsIgnoreCase("Lodge_Claim")) {
//				if (resource.equalsIgnoreCase("IC1"))
//					activityCost += 10;
//				else if (resource.equalsIgnoreCase("IC2"))
//					activityCost += 25;
//				else if (resource.equalsIgnoreCase("IC3"))
//					activityCost += 37;
//				else if (resource.equalsIgnoreCase("IC4"))
//					activityCost += 23;
//				else if (resource.equalsIgnoreCase("IC5"))
//					activityCost += 8;
//				else
//					activityCost += 2000;
//			} else if (task.equalsIgnoreCase("Review_Claim")) {
//				if (resource.equalsIgnoreCase("IC1"))
//					activityCost += 10;
//				else if (resource.equalsIgnoreCase("IC2"))
//					activityCost += 45;
//				else if (resource.equalsIgnoreCase("IC3"))
//					activityCost += 38;
//				else if (resource.equalsIgnoreCase("IC4"))
//					activityCost += 60;
//				else if (resource.equalsIgnoreCase("IC5"))
//					activityCost += 22;
//				else
//					activityCost += 2000;
//			} else if (task.equalsIgnoreCase("Appoint_Assessor")) {
//				if (resource.equalsIgnoreCase("IC1"))
//					activityCost += 18;
//				else if (resource.equalsIgnoreCase("IC2"))
//					activityCost += 50;
//				else if (resource.equalsIgnoreCase("IC3"))
//					activityCost += 5;
//				else if (resource.equalsIgnoreCase("IC4"))
//					activityCost += 13;
//				else if (resource.equalsIgnoreCase("IC5"))
//					activityCost += 30;
//				else
//					activityCost += 2000;
//			} else if (task.equalsIgnoreCase("Request_Assessment")) {
//				if (resource.equalsIgnoreCase("IC1"))
//					activityCost += 8;
//				else if (resource.equalsIgnoreCase("IC2"))
//					activityCost += 42;
//				else if (resource.equalsIgnoreCase("IC3"))
//					activityCost += 27;
//				else if (resource.equalsIgnoreCase("IC4"))
//					activityCost += 20;
//				else if (resource.equalsIgnoreCase("IC5"))
//					activityCost += 16;
//				else
//					activityCost += 2000;
//			} else if (task.equalsIgnoreCase("Assess_Car")) {
//				if (resource.equalsIgnoreCase("IAss1"))
//					activityCost += 78;
//				else if (resource.equalsIgnoreCase("IAss2"))
//					activityCost += 35;
//				else if (resource.equalsIgnoreCase("IAss3"))
//					activityCost += 53;
//				else
//					activityCost += 2000;
//			}  else if (task.equalsIgnoreCase("Assess_Customer")) {
//				if (resource.equalsIgnoreCase("IAss1"))
//					activityCost += 17;
//				else if (resource.equalsIgnoreCase("IAss2"))
//					activityCost += 35;
//				else if (resource.equalsIgnoreCase("IAss3"))
//					activityCost += 60;
//				else
//					activityCost += 2000;
//			}  else if (task.equalsIgnoreCase("Decide_Claim")) {
//				if (resource.equalsIgnoreCase("IM1"))
//					activityCost += 15;
//				else if (resource.equalsIgnoreCase("IM2"))
//					activityCost += 29;
//				else if (resource.equalsIgnoreCase("IM3"))
//					activityCost += 55;
//				else
//					activityCost += 2000;
//			}  else if (task.equalsIgnoreCase("Approve")) {
//				if (resource.equalsIgnoreCase("IAcc1"))
//					activityCost += 14;
//				else if (resource.equalsIgnoreCase("IAcc2"))
//					activityCost += 25;
//				else if (resource.equalsIgnoreCase("IAcc3"))
//					activityCost += 49;
//				else
//					activityCost += 2000;
//			}  else if (task.equalsIgnoreCase("Reject")) {
//				if (resource.equalsIgnoreCase("IAcc1"))
//					activityCost += 25;
//				else if (resource.equalsIgnoreCase("IAcc2"))
//					activityCost += 13;
//				else if (resource.equalsIgnoreCase("IAcc3"))
//					activityCost += 49;
//				else
//					activityCost += 2000;
//			}
			
			
		}
		//*/
		// Cost for resource (use resource, duration of activity, utilization rate of resource)
		//System.out.println("start");
		//int z = 0;
		//double resUtilization = 0.0;
		for (Activity a : candidate.getAbstractLog().getActivities()) {
			for (Resource r : candidate.getActivityResources(a)) {
				HORIZONSTART = candidate.getActivityStart(a) - HORIZON;
				
				double resourceUtilCount = 0, resourceUtilization = 0;
				
				resourceUtilCount = candidate.getResourceUtilization(r, HORIZON, HORIZONSTART);
				
				if (HORIZONSTART < 0) {
					resourceUtilization = 0.8;
				} else {
					resourceUtilization = (1.0 / HORIZON) * resourceUtilCount;
				}
				
				//double resourceUnitRate = ((1.0 / HORIZON) * (HORIZON - (HORIZON - resourceUtil)));
				//System.out.println(r.getId() + " = " + String.format("%.5f", resourceUtil) + " = " + String.format("%.5f", resourceUnitRate));
				//System.out.println(r.getId() + " = " + String.format("%.5f", resourceUtilization));
				//System.out.println(String.format("%.5f", resourceUtilization));
				//System.out.println(((120 * (resourceUnitRate * resourceUnitRate)) - (192 * resourceUnitRate) + 90));
				/*
				if (resourceUtilization >= 0.95) {
					resourceCost += 20 * resourceUtilCount; 
				} else {
					resourceCost += ((30 * (resourceUtilization * resourceUtilization)) - (50 * resourceUtilization) + 22) * resourceUtilCount;
					//resourceCost += ((15 * (resourceUtilization * resourceUtilization)) - (24 * resourceUtilization) + 11) * resourceUtilCount;
				}
				*/
				
				double rate = 0;
				
				if (resourceUtilization <= 0.15) {
					rate = 80.0;//System.out.println("wayUNDER");
				} else if (resourceUtilization <= 0.35) {
					rate = 55.0;//System.out.println("<=0.35");
				} else if (resourceUtilization <= 0.55) {
					rate = 30.0;//System.out.println("<=0.55");
				} else if (resourceUtilization <= 0.75) {
					rate = 15.0;//System.out.println("<=0.75");
				} else if (resourceUtilization <= 0.85) {
					rate = 5.0;//System.out.println("optimum");
				} else {
					rate = 40.0;//System.out.println("wayOVER");
				}
				
				resourceCost += rate * resourceUtilCount; 
				
				//resourceCost += (1 - resourceUtilization);
				//resUtilization += resourceUtilization;
				//z++;
			}
		}
		
		MultiObjectiveCostModel.caseCost = caseCost;
		MultiObjectiveCostModel.actCost = activityCost;
		MultiObjectiveCostModel.resCost = resourceCost;
		//MultiObjectiveCostModel.avgResUtil = (resUtilization/z);
		
		totalCost =  caseCost + activityCost + resourceCost;
		//System.out.println("cost -" + totalCost + " casecost -" + caseCost + " actcost -" + activityCost + " rescost -" + resourceCost);
		return totalCost;
	}
	
	public double calculateCostForDoubleTask(ConcreteEventLog candidate, double TIMEUNIT, long HORIZON, long HORIZONSTART) {
		double caseCost = 0, activityCost = 0, resourceCost = 0, totalCost = 0;
		
		// Cost for case (use duration and properties)
		for (Case c : candidate.getAbstractLog().getCases()) {
			String damage = null;
			double duration = ((double) candidate.getCaseDuration(c) / TIMEUNIT);
			//double durInHours = duration / 60;
			
			Iterator<Activity> it = c.getActivities().iterator();

			while (it.hasNext()) {
				Activity act = (Activity) it.next();
				if (act.getAttributes().containsKey("DamageType")) {
					damage = act.getAttributes().get("DamageType").toString();
					break;
				}
		    }
			
			if (damage.equalsIgnoreCase("Windscreen")) {
				caseCost += (4 * duration);
			} else if (damage.equalsIgnoreCase("DentsAndScratches")) {
				caseCost += (2 * duration);
			} else if (damage.equalsIgnoreCase("Collision")) {
				caseCost += (5 * duration);
			} else if (damage.equalsIgnoreCase("Thief")) {
				caseCost += (6 * duration);
			} else if (damage.equalsIgnoreCase("Fire")) {
				caseCost += (8 * duration);
			} else {
				caseCost += 0;
			}
			
			if (duration >= 480) {
				caseCost += 2000;
				
				double overrun = duration - 480;
				overrun = ((int) overrun / 60);
				caseCost += overrun * 200;
			}
			
			
			
		}
		///*
		for (Activity a : candidate.getAllActivity()) {
			String resource = candidate.getActivityResources(a).iterator().next().toString();
			String task = a.getTask().toString();
			
			if (task.equalsIgnoreCase("Lodge_Claim")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 10;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 25;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 37;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 23;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 8;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Review_Claim")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 10;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 45;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 38;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 60;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 22;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Appoint_Assessor")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 18;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 50;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 5;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 13;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 30;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Request_Assessment")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 8;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 42;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 27;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 20;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 16;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Assess_Car")) {
				if (resource.equalsIgnoreCase("IAss1"))
					activityCost += 78;
				else if (resource.equalsIgnoreCase("IAss2"))
					activityCost += 35;
				else if (resource.equalsIgnoreCase("IAss3"))
					activityCost += 53;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Assess_Customer")) {
				if (resource.equalsIgnoreCase("IAss1"))
					activityCost += 17;
				else if (resource.equalsIgnoreCase("IAss2"))
					activityCost += 35;
				else if (resource.equalsIgnoreCase("IAss3"))
					activityCost += 60;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Decide_Claim")) {
				if (resource.equalsIgnoreCase("IM1"))
					activityCost += 15;
				else if (resource.equalsIgnoreCase("IM2"))
					activityCost += 29;
				else if (resource.equalsIgnoreCase("IM3"))
					activityCost += 55;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Approve")) {
				if (resource.equalsIgnoreCase("IAcc1"))
					activityCost += 14;
				else if (resource.equalsIgnoreCase("IAcc2"))
					activityCost += 25;
				else if (resource.equalsIgnoreCase("IAcc3"))
					activityCost += 49;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Reject")) {
				if (resource.equalsIgnoreCase("IAcc1"))
					activityCost += 25;
				else if (resource.equalsIgnoreCase("IAcc2"))
					activityCost += 13;
				else if (resource.equalsIgnoreCase("IAcc3"))
					activityCost += 49;
				else
					activityCost += 1000;
			}
			
			
		}
		//*/
		// Cost for resource (use resource, duration of activity, utilization rate of resource)
		//System.out.println("start");
		//int z = 0;
		//double resUtilization = 0.0;
		for (Activity a : candidate.getAbstractLog().getActivities()) {
			for (Resource r : candidate.getActivityResources(a)) {
				HORIZONSTART = candidate.getActivityStart(a) - HORIZON;
				
				double resourceUtilCount = 0, resourceUtilization = 0;
				
				resourceUtilCount = candidate.getResourceUtilization(r, HORIZON, HORIZONSTART);
				
				if (HORIZONSTART < 0) {
					resourceUtilization = 0.8;
				} else {
					resourceUtilization = (1.0 / HORIZON) * resourceUtilCount;
				}
				
				//double resourceUnitRate = ((1.0 / HORIZON) * (HORIZON - (HORIZON - resourceUtil)));
				//System.out.println(r.getId() + " = " + String.format("%.5f", resourceUtil) + " = " + String.format("%.5f", resourceUnitRate));
				//System.out.println(r.getId() + " = " + String.format("%.5f", resourceUtilization));
				//System.out.println(String.format("%.5f", resourceUtilization));
				//System.out.println(((120 * (resourceUnitRate * resourceUnitRate)) - (192 * resourceUnitRate) + 90));
				/*
				if (resourceUtilization >= 0.95) {
					resourceCost += 20 * resourceUtilCount; 
				} else {
					resourceCost += ((30 * (resourceUtilization * resourceUtilization)) - (50 * resourceUtilization) + 22) * resourceUtilCount;
					//resourceCost += ((15 * (resourceUtilization * resourceUtilization)) - (24 * resourceUtilization) + 11) * resourceUtilCount;
				}
				*/
				
				double rate = 0;
				
				if (resourceUtilization <= 0.15) {
					rate = 45.0;//System.out.println("wayUNDER");
				} else if (resourceUtilization <= 0.25) {
					rate = 36.0;//System.out.println("UNDER");
				} else if (resourceUtilization <= 0.35) {
					rate = 28.0;//System.out.println("<=0.35");
				} else if (resourceUtilization <= 0.45) {
					rate = 21.0;//System.out.println("<=0.45");
				} else if (resourceUtilization <= 0.55) {
					rate = 15.0;//System.out.println("<=0.55");
				} else if (resourceUtilization <= 0.65) {
					rate = 10.0;//System.out.println("<=0.65");
				} else if (resourceUtilization <= 0.75) {
					rate = 6.0;//System.out.println("<=0.75");
				} else if (resourceUtilization <= 0.85) {
					rate = 1.0;//System.out.println("optimum");
				} else if (resourceUtilization <= 0.9) {
					rate = 10.0;//System.out.println("over");
				} else {
					rate = 20.0;//System.out.println("wayOVER");
				}
				
				resourceCost += rate * resourceUtilCount; 
				
				//resourceCost += (1 - resourceUtilization);
				//resUtilization += resourceUtilization;
				//z++;
			}
		}
		
		MultiObjectiveCostModel.caseCost = caseCost;
		MultiObjectiveCostModel.actCost = activityCost;
		MultiObjectiveCostModel.resCost = resourceCost;
		//MultiObjectiveCostModel.avgResUtil = (resUtilization/z);
		
		totalCost =  caseCost + activityCost + resourceCost;
		//System.out.println("cost -" + totalCost + " casecost -" + caseCost + " actcost -" + activityCost + " rescost -" + resourceCost);
		return totalCost;
	}
	
	public double calculateCostForDoubleCase(ConcreteEventLog candidate, double TIMEUNIT, long HORIZON, long HORIZONSTART) {
		double caseCost = 0, activityCost = 0, resourceCost = 0, totalCost = 0;
		
		// Cost for case (use duration and properties)
		for (Case c : candidate.getAbstractLog().getCases()) {
			String damage = null;
			double duration = ((double) candidate.getCaseDuration(c) / TIMEUNIT);
			//double durInHours = duration / 60;
			
			Iterator<Activity> it = c.getActivities().iterator();

			while (it.hasNext()) {
				Activity act = (Activity) it.next();
				if (act.getAttributes().containsKey("DamageType")) {
					damage = act.getAttributes().get("DamageType").toString();
					break;
				}
		    }
			
			if (damage.equalsIgnoreCase("Windscreen")) {
				caseCost += (4 * duration);
			} else if (damage.equalsIgnoreCase("DentsAndScratches")) {
				caseCost += (2 * duration);
			} else if (damage.equalsIgnoreCase("Collision")) {
				caseCost += (5 * duration);
			} else if (damage.equalsIgnoreCase("Thief")) {
				caseCost += (6 * duration);
			} else if (damage.equalsIgnoreCase("Fire")) {
				caseCost += (8 * duration);
			} else {
				caseCost += 0;
			}
			
			if (duration >= 420) {
				caseCost += 2000;
				
				double overrun = duration - 420;
				overrun = ((int) overrun / 60);
				caseCost += overrun * 200;
			}
			
			
			
		}
		///*
		for (Activity a : candidate.getAllActivity()) {
			String resource = candidate.getActivityResources(a).iterator().next().toString();
			String task = a.getTask().toString();
			
			if (task.equalsIgnoreCase("Lodge_Claim")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 10;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 25;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 37;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 23;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 8;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Review_Claim")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 10;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 45;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 38;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 60;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 22;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Appoint_Assessor")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 18;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 50;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 5;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 13;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 30;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Request_Assessment")) {
				if (resource.equalsIgnoreCase("IC1"))
					activityCost += 8;
				else if (resource.equalsIgnoreCase("IC2"))
					activityCost += 42;
				else if (resource.equalsIgnoreCase("IC3"))
					activityCost += 27;
				else if (resource.equalsIgnoreCase("IC4"))
					activityCost += 20;
				else if (resource.equalsIgnoreCase("IC5"))
					activityCost += 16;
				else
					activityCost += 1000;
			} else if (task.equalsIgnoreCase("Assess_Car")) {
				if (resource.equalsIgnoreCase("IAss1"))
					activityCost += 78;
				else if (resource.equalsIgnoreCase("IAss2"))
					activityCost += 35;
				else if (resource.equalsIgnoreCase("IAss3"))
					activityCost += 53;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Assess_Customer")) {
				if (resource.equalsIgnoreCase("IAss1"))
					activityCost += 17;
				else if (resource.equalsIgnoreCase("IAss2"))
					activityCost += 35;
				else if (resource.equalsIgnoreCase("IAss3"))
					activityCost += 60;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Decide_Claim")) {
				if (resource.equalsIgnoreCase("IM1"))
					activityCost += 15;
				else if (resource.equalsIgnoreCase("IM2"))
					activityCost += 29;
				else if (resource.equalsIgnoreCase("IM3"))
					activityCost += 55;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Approve")) {
				if (resource.equalsIgnoreCase("IAcc1"))
					activityCost += 14;
				else if (resource.equalsIgnoreCase("IAcc2"))
					activityCost += 25;
				else if (resource.equalsIgnoreCase("IAcc3"))
					activityCost += 49;
				else
					activityCost += 1000;
			}  else if (task.equalsIgnoreCase("Reject")) {
				if (resource.equalsIgnoreCase("IAcc1"))
					activityCost += 25;
				else if (resource.equalsIgnoreCase("IAcc2"))
					activityCost += 13;
				else if (resource.equalsIgnoreCase("IAcc3"))
					activityCost += 49;
				else
					activityCost += 1000;
			}
			
			
		}
		//*/
		// Cost for resource (use resource, duration of activity, utilization rate of resource)
		//System.out.println("start");
		//int z = 0;
		//double resUtilization = 0.0;
		for (Activity a : candidate.getAbstractLog().getActivities()) {
			for (Resource r : candidate.getActivityResources(a)) {
				HORIZONSTART = candidate.getActivityStart(a) - HORIZON;
				
				double resourceUtilCount = 0, resourceUtilization = 0;
				
				resourceUtilCount = candidate.getResourceUtilization(r, HORIZON, HORIZONSTART);
				
				if (HORIZONSTART < 0) {
					resourceUtilization = 0.8;
				} else {
					resourceUtilization = (1.0 / HORIZON) * resourceUtilCount;
				}
				
				//double resourceUnitRate = ((1.0 / HORIZON) * (HORIZON - (HORIZON - resourceUtil)));
				//System.out.println(r.getId() + " = " + String.format("%.5f", resourceUtil) + " = " + String.format("%.5f", resourceUnitRate));
				//System.out.println(r.getId() + " = " + String.format("%.5f", resourceUtilization));
				//System.out.println(String.format("%.5f", resourceUtilization));
				//System.out.println(((120 * (resourceUnitRate * resourceUnitRate)) - (192 * resourceUnitRate) + 90));
				/*
				if (resourceUtilization >= 0.95) {
					resourceCost += 20 * resourceUtilCount; 
				} else {
					resourceCost += ((30 * (resourceUtilization * resourceUtilization)) - (50 * resourceUtilization) + 22) * resourceUtilCount;
					//resourceCost += ((15 * (resourceUtilization * resourceUtilization)) - (24 * resourceUtilization) + 11) * resourceUtilCount;
				}
				*/
				
				double rate = 0;
				
				if (resourceUtilization <= 0.15) {
					rate = 45.0;//System.out.println("wayUNDER");
				} else if (resourceUtilization <= 0.25) {
					rate = 36.0;//System.out.println("UNDER");
				} else if (resourceUtilization <= 0.35) {
					rate = 28.0;//System.out.println("<=0.35");
				} else if (resourceUtilization <= 0.45) {
					rate = 21.0;//System.out.println("<=0.45");
				} else if (resourceUtilization <= 0.55) {
					rate = 15.0;//System.out.println("<=0.55");
				} else if (resourceUtilization <= 0.65) {
					rate = 10.0;//System.out.println("<=0.65");
				} else if (resourceUtilization <= 0.75) {
					rate = 6.0;//System.out.println("<=0.75");
				} else if (resourceUtilization <= 0.85) {
					rate = 1.0;//System.out.println("optimum");
				} else if (resourceUtilization <= 0.9) {
					rate = 10.0;//System.out.println("over");
				} else {
					rate = 20.0;//System.out.println("wayOVER");
				}
				
				resourceCost += rate * resourceUtilCount; 
				
				//resourceCost += (1 - resourceUtilization);
				//resUtilization += resourceUtilization;
				//z++;
			}
		}
		
		MultiObjectiveCostModel.caseCost = caseCost;
		MultiObjectiveCostModel.actCost = activityCost;
		MultiObjectiveCostModel.resCost = resourceCost;
		//MultiObjectiveCostModel.avgResUtil = (resUtilization/z);
		
		totalCost =  caseCost + activityCost + resourceCost;
		//System.out.println("cost -" + totalCost + " casecost -" + caseCost + " actcost -" + activityCost + " rescost -" + resourceCost);
		return totalCost;
	}
}
